<?php
namespace app\manager\controller;

class CarCate extends BaseController
{
    protected $check_auths = false; 
    /**
     * GET shwo carcate info list
     * @return [type] [description]
     */
    public function index()
    {
        $list = model('CarCates')->getCarCateList();
        $this->assign('list',$list);//dump($list);die;
        return view('p/carcate/index');
    }
    /**
     * GET show carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {
        echo "string";
    }

    /**
     * GET shwo create carcate info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('p/carcate/create');
    }
    /**
     * POST create new carcate info
     * @return [type] [description]
     */
    public function save()
    {
        $post_carcate_info['name'] = input('post.name');
        $post_carcate_info['profiles'] = input('post.profiles');

        $carcate = model('CarCates')->createCarCate($post_carcate_info);

        if($carcate){
            return $this->success(lang('create carcate success'), '/carcate');
        }
            return $this->error(lang('create carcate failed').$carcate['msg']);

    }
    /**
     * GET edit carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $data = model('CarCates')->getCarCateInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/carcate/edit');
    }
    /**
     * PUT update carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {

        $post_carcate_info['name'] = input('post.name');
        $post_carcate_info['profiles'] = input('post.profiles');
        
        $carcate = model('CarCates')->updateCarCate($id, $post_carcate_info);

        if($carcate){
            return $this->success(lang('update carcate success'), '/carcate');
        }
            return $this->error(lang('update carcate failed').$carcate['msg']);

    }
    
    /**
     * DELETE carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('CarCates')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/carcate');
        }
        return $this->error('删除失败');
    }
    
   
}

